
<template>
  <div id="box">
    <div class="otherDisposal">
      <div class="disposal">
        <!-- <div v-show="treatmentList.length === 0 && medicineList.length === 0">
          <center><h3>无数据</h3></center>
        </div> -->
        <div class="addContent">
          <el-button
            type="primary"
            style="float: right;margin-right: 40px;margin-top: 8px;padding: 8px 15px;"
            @click="popup"
          >新增药物</el-button>
          <el-button
            type="primary"
            style="float: right;margin-right: 40px;margin-top: 8px;padding: 8px 15px;"
            @click="popupLife"
          >新增生命支持</el-button>
        </div>
        <div v-show="treatmentList.length" class="lifeSupport">
          <div class="text-life">生命支持</div>
          <div v-for="(item, index) in treatmentList" :key="index" class="life-box">
            <span class="line" />
            <div class="life-lift">
              <el-checkbox-group v-model="item.treatment" class="life-many">
                <el-checkbox label="吸氧" />
                <el-checkbox label="心电监护" />
                <el-checkbox label="心肺复苏" />
                <el-checkbox label="气管插管" />
                <el-checkbox label="开通静脉通路" />
              </el-checkbox-group>
            </div>
            <div class="life-right">
              <span class="jizhen-text">{{ item.time }}</span>
              <!-- <span>北票市人民医院</span> -->
              <span class="jizhen-text">{{ item.department }}</span>
              <span>{{ item.doctor }}</span>
            </div>
            <div class="life-bottom">
              <div class="beizhutext">备注：</div>
              <el-input v-model="item.notes" placeholder="请输入内容" style="width:96%" @change="handleLifeText">
                {{ item.notes }}
              </el-input>
            </div>
            <!-- <el-button type="primary" size="mini" style="position: absolute;right: 10px;bottom: 0px; width: 80px;" @click="lifeTreatments(index)">保存</el-button> -->
          </div>
        </div>
        <div v-show="medicineList.length" class="drug">
          <div class="text-life">药物</div>
          <div v-for="(medicieneItem, target) in medicineList" :key="target" class="life-box">
            <el-button type="primary" size="small" style="position: absolute;right: 10px;bottom: 0px; width: 80px;" @click="saveMedicine(target)">保存</el-button>
            <span class="line" />
            <div class="life-lift">
              <!-- <el-button-group>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.dapt;modelData.checkList = medicieneItem.drugArr;Subscript = target">抗血小板药</el-button>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.anticoagulant;modelData.checkList = medicieneItem.drugArr;Subscript = target">抗凝药</el-button>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.antihypertensived;modelData.checkList = medicieneItem.drugArr;Subscript = target">降压药</el-button>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.hypoglycemic;modelData.checkList = medicieneItem.drugArr;Subscript = target">降糖药</el-button>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.reduction;modelData.checkList = medicieneItem.drugArr;Subscript = target">调脂药</el-button>
                <el-button type="info" round @click="innerVisible = true; modelData.drugTemplate = chestPain.vasospasm;modelData.checkList = medicieneItem.drugArr;Subscript = target">抗血管痉挛药</el-button>
              </el-button-group> -->
              <div class="box-card" shadow="hover" style="margin-top: 10px;">
                <el-form label-position="right" label-width="100px">
                  <div style="border: #e4e4e4 solid 1px; padding: 10px 10px 10px 0; min-height: 100px;">
                    <div v-for="(item, index) in JSON.parse(medicieneItem.chipsOrder.json).orderDetail" :key="index">
                      <el-row :gutter="24" style="padding: 5px 0px 5px 30px;line-height: 40px;">
                        <el-col :span="2">{{ index+1 }}</el-col>
                        <el-col :span="4">{{ item.itemName }}</el-col>
                        <el-col :span="4"> {{ item.medicineName }}</el-col>
                        <el-col :span="4">
                          <el-input v-model.trim="item.dosage" disabled />
                        </el-col>
                        <el-col :span="4">
                          <!-- <el-select v-model="item.unit " placeholder="请选择">
                            <el-option value="mg" />
                            <el-option value="ml" />
                            <el-option value="IU" />
                            <el-option value="片" />
                          </el-select> -->
                          <el-input v-model="item.unit" disabled placeholder="" />
                        </el-col>
                        <!-- <el-col :span="6">
                          <el-date-picker
                            v-model="item.medicineTime"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择日期时间" />
                        </el-col> -->
                        <!-- <el-col :span="2">
                          <el-button type="danger" plain @click="delDrugIndex(index,item.medicineName, target )">删除</el-button>
                        </el-col> -->
                      </el-row>
                    </div>
                  </div>
                </el-form>
              </div>
              <el-dialog width="60%" title="选择药物" :visible.sync="innerVisible" append-to-body style="text-align: center;">
                <el-checkbox-group v-model="modelData.checkList">
                  <el-checkbox
                    v-for="(items,$index) in modelData.drugTemplate"
                    :key="$index"
                    :label="items"
                    border
                    style="margin-bottom: 10px;"
                    @change="addDelList(items,$index)"
                  />
                </el-checkbox-group>
                <span slot="footer" class="dialog-footer">
                  <el-button type="primary" @click="innerVisible = false">确 定</el-button>
                </span>
              </el-dialog>
            </div>
            <div class="life-right">
              <span class="jizhen-text">{{ medicieneItem.time }}</span>
              <!-- <span>北票市人民医院</span> -->
              <span class="jizhen-text">{{ medicieneItem.department }}</span>
              <span>{{ medicieneItem.doctor }}</span>
            </div>
            <div class="life-bottom">
              <div class="beizhutext">备注：</div>
              <el-input v-model="medicieneItem.chipsOrder.notes" placeholder="请输入内容" style="width:80%" @change="handleDrugText">
                {{ medicieneItem.chipsOrder.notes }}
              </el-input>
            </div>
            <!-- <el-button type="primary" size="mini" style="position: absolute;right: 10px;top: 0px; width: 80px;" @click="saveMedicine(target)">保存</el-button> -->
          </div>
        </div>
      </div>
    </div>
    <!-- 新增药物 -->
    <el-dialog
      title="新增药物"
      :visible.sync="rapidDispensingChange"
      class="dialogStyle"
      width="750px"
      top="18vh"
      :close-on-click-modal="false"
    >
      <div style="display: flex;justify-content:space-around;flex-wrap:wrap">
        <el-button
          v-for="(item,index) in drugType"
          :key="index"
          type="primary"
          round
          style="width:200px;margin:5px 0px;"
          @click="addInnerVisible = true; addNoRepetitionDrug(item);addModelData.tempName = index"
        >{{ index }}</el-button>
      </div>
      <div class="box-card" shadow="hover" style="margin-top: 15px;">
        <el-form label-position="right" label-width="100px">
          <div style="border: #eee solid 1px; padding: 10px 15px 10px 5px; min-height: 100px;">
            <div v-for="(item,index) in saveList" :key="index">
              <el-row :gutter="20" style="padding: 10px;line-height: 40px;">
                <el-col :span="1">{{ index+1 }}</el-col>
                <el-col :span="4"> {{ item.itemName }}</el-col>
                <el-col :span="8"> {{ item.medicineName }}</el-col>
                <el-col :span="4">
                  <el-input v-model.trim="item.dosage" />
                </el-col>
                <el-col :span="4">
                  <el-select v-model="item.unit " placeholder="请选择">
                    <el-option v-for="(el,index) in func(item.medicineUnit)" :key="index" :value="el" />
                    <!-- <el-option value="ml" />
                    <el-option value="IU" />
                    <el-option value="片" /> -->
                  </el-select>
                </el-col>
                <el-col :span="2">
                  <el-button type="danger" plain @click="deleteAnItem(index,item.medicineName )">删除</el-button>
                </el-col>
              </el-row>
            </div>
          </div>
          <el-row style="margin-top: 20px;">
            <el-col :span="24">
              <span style="font-size: 16px;">备注 : </span>
              <el-input v-model="remarks" placeholder="请输入内容" style="width: 92%;" clearable />
            </el-col>
          </el-row>
        </el-form>
      </div>
      <el-dialog width="60%" title="选择药物" :visible.sync="addInnerVisible" append-to-body style="text-align: center;">
        <el-checkbox-group v-model="addModelData.checkList">
          <el-checkbox
            v-for="(items,$index) in addModelData.drugTemplate"
            :key="$index"
            :label="items"
            border
            style="margin-bottom: 10px;"
            @change="addDeleteList(items,$index,addModelData.tempName)"
          />
        </el-checkbox-group>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="addInnerVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <span slot="footer" class="dialog-footer">
        <el-button @click="rapidDispensingChange = false">取 消</el-button>
        <el-button type="primary" @click="saveData()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="新增生命支持"
      :visible.sync="lifeChange"
      class="dialogStyle"
      width="60%"
      top="15px"
      :close-on-click-modal="false"
    >
      <div class="box-card" shadow="hover" style="margin-top: 15px;">
        <el-form label-position="right" label-width="100px">
          <div style="border: #eee solid 1px; padding: 30px 15px 10px 0; min-height: 80px;">
            <el-checkbox-group v-model="lifeTreatment" class="life-many">
              <el-checkbox label="吸氧" />
              <el-checkbox label="心电监护" />
              <el-checkbox label="心肺复苏" />
              <el-checkbox label="气管插管" />
              <el-checkbox label="开通静脉通路" />
            </el-checkbox-group>
          </div>
          <el-row :gutter="24" style="margin-top: 20px;">
            <el-col :span="24">
              <span style="font-size: 16px;display: inline-block;margin-right: 30px;">备 注 :</span>
              <el-input v-model="lifeRemarks" placeholder="请输入内容" style="width: 90%;display: inline-block;" clearable />
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="lifeClearAll(),lifeChange = false">取 消</el-button>
        <el-button type="primary" @click="addSaveLife()">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { queryListDisGet, saveOtherTreatments, saveOtherMedicineg, selectList } from '@/api/green-channel/otherDisposal'
import qs from 'qs'
export default {
  name: 'OtherDisposalStroke',
  props: ['checkrowdata'], // 由主页面(父组件) 接收来的, 选择项的数据
  data() {
    return {
      /* 药品信息 */
      drugList: [],
      drugType: [], // 药品类型

      /* 新增生命支持 ------ */
      lifeChange: false,
      lifeTreatment: [],
      lifeRemarks: '',
      /* end -------------- */
      /* 新增药物 --------------------------- */
      rapidDispensingChange: false,
      addInnerVisible: false,
      saveList: [], // 弹出页面下方
      addModelData: { // dialog数据
        id: '',
        tempName: '',
        checkList: [], // 小弹出选中的多选-存值
        drugTemplate: [] // 小弹出可选的多选值
      },
      remarks: '',
      /* end ---------------------------- */

      dispatchIdInFo: {
        dispatchId: ''
      },
      Subscript: '',
      supportLift: [], // 生命复选值
      isSelected: true,
      treatmentList: [], // 生命支持列表
      lifeText: '', // 生命支持备注
      saveLifeData: {
        medicalid: this.checkrowdata.medicalId,
        dispatchId: this.checkrowdata.dispatchId,
        userId: this.checkrowdata.userId,
        treatment: [],
        user: '',
        department: this.checkrowdata.departmentName,
        notes: ''
      }, // 生命支持参数
      drugText: '', // 药物备注
      medicineList: [], // 药物列表
      saveMedicineData: {
        userId: '',
        missionId: '',
        medicalId: '',
        instanceType: '',
        json: {},
        status: 1,
        notes: '',
        polarity: '',
        version: '',
        judgement: '',
        hasAudio: false,
        hasPhoto: false,
        module: '',
        doctor: '',
        department: ''
      }, // 药物参数
      // value4: '0',
      // activeName: 'second',
      medicineType: '卒中',
      innerVisible: false,
      modelData: { // dialog数据
        id: '',
        tempName: '',
        checkList: [], // 小弹出选中的多选-存值
        drugTemplate: [] // 小弹出可选的多选值
      },
      chestPain: {
        /* 抗血小板药*/
        dapt: ['阿司匹林', '替格瑞洛', '氯吡格雷', '替罗非班', '阿西单抗', '普拉格雷', '依替巴肽', '西洛他挫', '奥扎格雷', '双嘧达莫', '塞氯吡啶'],
        /* 抗凝药 */
        anticoagulant: ['普通肝素', '双香豆素', '依诺肝素', '替他肝素', '阿地肝素', '华法林', '硝酸香豆素', '枸橼酸钠', '磺达肝葵钠', '比伐卢定', '利伐沙班', '达比加群',
          '阿哌沙班',
          '依度沙班', '低分子肝素'
        ],
        /* 降压药*/
        antihypertensived: ['ACEI', 'ARB', '利尿剂', 'β受体阻滞剂', '钙拮抗剂'],
        /* 降糖药*/
        hypoglycemic: ['胰岛素', '磺酰脲类', '双胍类', 'α糖苷酶抑制剂', '胰岛素增敏剂', '非磺酰脲类促胰岛素分泌剂'],
        /* 调脂药*/
        reduction: ['他汀类', '烟酸及其衍生物', '贝特类', '胆固醇吸收抑制剂'],
        // 抗血管痉挛药
        vasospasm: ['尼莫地平', '法舒地尔']
      },
      drugArrList: [] // 药物复选框选中数组
    }
  },
  mounted() {
    console.log('this.$store.getters', this.$store.getters)
    this.getLifeDrug()
  },
  methods: {
    func(unit) {
      const arr = ['mg', 'ml', 'IU', '片']
      if (!arr.includes(unit) && unit !== undefined) {
        arr.unshift(...unit)
      }
      return Array.from(new Set(arr))
    },

    /* 新增生命支持 ------------------- */
    popupLife() {
      this.lifeChange = true
    },
    // 保存
    addSaveLife() {
      if (!this.lifeTreatment || this.lifeTreatment.length === 0) {
        this.$message({
          message: `请选择生命支持具体选项`,
          type: 'warning'
        })
        return false
      }
      const lifeTreatment = this.lifeTreatment.join(',')
      const lifeData = {
        'medicalid': this.checkrowdata.medicalId,
        'dispatchId': this.checkrowdata.dispatchId,
        'department': this.checkrowdata.departmentName,
        notes: this.lifeRemarks,
        userId: this.checkrowdata.userId,
        id: null,
        treatment: JSON.stringify(this.lifeTreatment)
      }
      saveOtherTreatments(lifeData)
        .then(res => {
          if (res.code === 0) {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            this.lifeChange = false
            this.lifeClearAll()
            this.getLifeDrug()
          } else {
            this.$message({
              message: '保存失败',
              type: 'error'
            })
          }
        })
        .catch(() => {
          this.$message({
            message: '保存失败',
            type: 'error'
          })
        })
    },

    lifeClearAll() {
      this.lifeTreatment = []
      this.lifeRemarks = ''
    },
    /* end --------------------------- */

    /* 新增药物 ------------------------*/
    /* 点击button */
    popup() {
      this.rapidDispensingChange = true
      this.clearAll()
    },
    addDeleteList(medicine, index, type) { // 根据点击多选增减下方药物列表
      /* 发生change事件运行至此,已完成对数组checkList的增减, 在此相应对saveList做出增减*/
      const arrIndex = this.addModelData.checkList.indexOf(medicine)
      if (arrIndex === -1) { // 若不存在,说明该药物被取消选中
        this.DeleteDrugName(medicine) // 根据药名删除药品
      } else { // 若存在,说明该药物被选中
        this.addToDrugName(medicine, type) // 故根据药名向saveList添加药品
      }
    },
    addToDrugName(name, type) { // 根据药名向saveList添加药品
      // 根据药物类型/名称查找默认单位
      const _data = this.drugList.filter(item => item['medicineType'] === type && item['medicineName'] === name)
      const medicineUnit = []
      _data.forEach((item) => {
        medicineUnit.push(item.medicineUnit)
      })
      this.saveList.push({
        itemName: type,
        medicineName: name,
        dosage: '',
        unit: _data[0].medicineUnit,
        medicineUnit: medicineUnit
      })
    },
    DeleteDrugName(name) { // 根据药名删除药品
      let arrIndex = ''
      this.saveList.forEach((el, index) => {
        if (el.medicineName === name) {
          arrIndex = index
          return
        }
      })
      if (arrIndex !== '') { /* 注意这里 ( 0!="") ->false      */
        this.saveList.splice(arrIndex, 1)
      }
    },
    deleteAnItem(index, drueName, target) {
  	  // 药品删除按钮(根据索引)
      this.saveList.splice(index, 1)
      const arrIndex = this.addModelData.checkList.indexOf(drueName)
      this.addModelData.checkList.splice(arrIndex, 1)
    },

    saveData() {
      for (const el in this.saveList) {
        if (!this.saveList[el].dosage) {
          const emptyCheck = this.saveList[el].medicineName
          this.$message({
            message: `药物 ${emptyCheck} 剂量不能为空`,
            type: 'warning'
          })
          return false
        }
        if (!this.saveList[el].unit) {
          const emptyCheck = this.saveList[el].medicineName
          this.$message({
            message: `药物 ${emptyCheck} 单位不能为空`,
            type: 'warning'
          })
          return false
        }
      }
      for (const i in this.saveList) {
        this.saveList[i].medicineUnit = undefined
      }
      const newJson = {
        orderDetail: []
      }
      newJson.orderDetail = this.saveList
      const data = {
        // userId: this.checkrowdata.userId,
        userId: this.$store.getters.userId,
        missionId: this.checkrowdata.dispatchId,
        medicalId: this.checkrowdata.medicalId,
        instanceType: 'medicine',
        json: JSON.stringify(newJson),
        status: 1,
        notes: this.remarks,
        polarity: 0,
        version: 0,
        judgement: 0,
        module: '药物',
        // doctor: this.checkrowdata.doctorName,
        doctor: this.$store.getters.name,
        department: this.checkrowdata.departmentName
        // id : null
      }
      saveOtherMedicineg(qs.stringify(data)).then(res => {
        if (res.code === 0) {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.rapidDispensingChange = false
          this.clearAll()
          this.getLifeDrug()
        } else {
          this.$message({
            message: res.error,
            type: 'error'
          })
        }
      }).catch(() => {
        this.$message({
          message: '保存失败',
          type: 'error'
        })
      })
    },
    // 恢复默认值
    clearAll() { // 清除全部值
      this.addModelData.id = ''
      this.addModelData.tempName = ''
      this.addModelData.checkList = []
      this.addModelData.drugTemplate = []
      this.saveList = []
      this.remarks = ''
    },

    /* end ---------------------------------- */
    // 药品类去重
    addNoRepetitionDrug(item) {
      this.addModelData.drugTemplate = Array.from(new Set(item))
    },

    addDelList(medicine, index) { // 根据点击多选增减下方药物列表
      /* 发生change事件运行至此,已完成对数组checkList的增减, 在此相应对orderDetail做出增减*/
      let medicineListIndex
      for (medicineListIndex in this.medicineList) {
        if (medicineListIndex === this.Subscript.toString()) {
          const arrIndex = this.modelData.checkList.indexOf(medicine)
          if (arrIndex === -1) { // 若不存在,说明该药物被取消选中
            this.delDrugName(medicine, index) // 根据药名删除药品
          } else { // 若存在,说明该药物被选中
            this.addDrugName(medicine, index) // 故根据药名向orderDetail添加药品
          }
        }
      }
    },
    delDrugIndex(index, drueName, target) { // 药品删除按钮(根据索引)
      this.medicineList[target].chipsOrder.json.orderDetail.splice(index, 1)
      this.medicineList[target].drugArr.splice(index, 1)
    },
    delDrugName(name, ind) { // 根据药名删除药品
      let medicineListIndex
      for (medicineListIndex in this.medicineList) {
        if (medicineListIndex === this.Subscript.toString()) {
          let arrIndex = ''
          this.medicineList[this.Subscript].chipsOrder.json.orderDetail.forEach((el, index) => {
            if (el.medicineName === name) {
              arrIndex = index
              return
            }
          })
          if (arrIndex !== '') { /* 注意这里 ( 0!="") ->false      */
            this.medicineList[this.Subscript].chipsOrder.json.orderDetail.splice(arrIndex, 1)
          }
          this.medicineList[this.Subscript].drugArr.splice(name, 1)
        }
      }
    },
    addDrugName(name, index) { // 根据药名向saveList添加药品
      let type = ''
      if (this.medicineType === '卒中') {
        type = this.chestPain.dapt.indexOf(name) > -1 ? '抗血小板药' : type
        type = this.chestPain.anticoagulant.indexOf(name) > -1 ? '抗凝药' : type
        type = this.chestPain.antihypertensived.indexOf(name) > -1 ? '降压药' : type
        type = this.chestPain.hypoglycemic.indexOf(name) > -1 ? '降糖药' : type
        type = this.chestPain.reduction.indexOf(name) > -1 ? '调脂药' : type
        type = this.chestPain.vasospasm.indexOf(name) > -1 ? '抗血管痉挛药' : type
      } else {
        return
      }
      let medicineListIndex
      for (medicineListIndex in this.medicineList) {
        if (medicineListIndex === this.Subscript.toString()) {
          this.medicineList[this.Subscript].drugArr.push(name)
          this.medicineList[this.Subscript].chipsOrder.json.orderDetail.push({
            dosage: '',
            itemName: type,
            medicineName: name,
            unit: 'mg'
          })
        }
        // if (this.modelData.checkList.indexOf(name) === this.medicineList[this.Subscript].drugArr.indexOf(name)) {}
      }
    },
    // 生命支持备注
    handleLifeText(value) {
      this.lifeText = value
      this.saveLifeData.notes = value
    },
    // 生命支持保存
    lifeTreatments(val) {
      for (let j = val; j < val + 1; j++) {
        if (val === j) {
          const saveLifeData = this.saveLifeData
          this.saveLifeData.notes = this.treatmentList[val].notes
          this.saveLifeData.user = this.treatmentList[val].userId
          this.saveLifeData.id = this.treatmentList[val].id
          this.saveLifeData.treatment = JSON.stringify(this.treatmentList[val].treatment)
          saveOtherTreatments(saveLifeData).then(res => {
            this.$message({
            	message: '保存成功',
            	type: 'success'
            })
          }).catch(() => {
            this.$message({
            	message: '保存失败',
            	type: 'error'
            })
          })
        } else {
          return
        }
      }
    },
    // 药物备注
    handleDrugText(value) {
      this.lifeText = value
      this.saveMedicineData.notes = value
    },
    // 药物种类确定
    // 药物保存
    saveMedicine(val) {
      for (let j = val; j < val + 1; j++) {
        if (val === j) {
          console.log(this.medicineList[val].chipsOrder, 'chipsOrder')
          console.log(this.checkrowdata, 'this.checkrowdata')
          this.saveMedicineData.userId = this.$store.getters.userId
          // this.saveMedicineData.userId = this.medicineList[val].chipsOrder.userId
          this.saveMedicineData.missionId = this.medicineList[val].chipsOrder.missionId
          this.saveMedicineData.medicalId = this.medicineList[val].chipsOrder.medicalId
          this.saveMedicineData.instanceType = this.medicineList[val].chipsOrder.instanceType
          // this.saveMedicineData.json = this.medicineList[val].chipsOrder.json
          this.saveMedicineData.json = this.medicineList[val].chipsOrder.json
          this.saveMedicineData.status = this.medicineList[val].chipsOrder.status
          this.saveMedicineData.notes = this.medicineList[val].chipsOrder.notes
          this.saveMedicineData.polarity = this.medicineList[val].chipsOrder.polarity
          this.saveMedicineData.version = this.medicineList[val].chipsOrder.version
          this.saveMedicineData.judgement = this.medicineList[val].chipsOrder.judgement
          this.saveMedicineData.module = this.medicineList[val].chipsOrder.module
          // this.saveMedicineData.doctor = this.medicineList[val].chipsOrder.doctor
          this.saveMedicineData.doctor = this.$store.getters.name
          this.saveMedicineData.department = this.medicineList[val].chipsOrder.department
          this.saveMedicineData.id = this.medicineList[val].chipsOrder.id

          const saveMedicineData = this.saveMedicineData
          console.log('saveMedicineData', saveMedicineData)
          saveOtherMedicineg(qs.stringify(saveMedicineData)).then(res => {
            this.$message({
            	message: '保存成功',
            	type: 'success'
            })
            this.getLifeDrug()
          }).catch(() => {
            this.$message({
            	message: '保存失败',
            	type: 'error'
            })
          })
        } else {
          return
        }
      }
    },
    // 获取数据---------------
    getLifeDrug() {
      // 药品信息
      const DrugInformationData = {
      	pageNum: '',
      	pageSize: '',
      	apiToken: this.$store.getters.apiToken,
      	greenType: '卒中',
      	medicineType: ''
      }
      selectList(DrugInformationData).then(res => {
      	if (res.code === 0) {
          this.drugList = res.data.list
          const drugObj = {}
          res.data.list.forEach(item => {
            const array = drugObj[item['medicineType']] || []
            array.push(item.medicineName)
            drugObj[item['medicineType']] = array
          })
          this.drugType = drugObj
        }
      }).catch((err) => {
        this.$message.error(err)
      })

      // { dispatchId: 103148 }  //回显数据
      this.dispatchIdInFo.dispatchId = this.checkrowdata.dispatchId
      const data = this.dispatchIdInFo
      queryListDisGet(data).then(res => {
        this.treatmentList = []
        this.medicineList = []
        this.drugArrList = []
        const dataArr = res.data
        for (let i = 0; i < dataArr.length; i++) {
          if (dataArr[i].datatype === 'treatment') {
            this.treatmentList.push(dataArr[i])
          } else if (dataArr[i].datatype === 'medicine') {
            for (let j = 0; j < JSON.parse(dataArr[i].chipsOrder.json).orderDetail.length; j++) {
              let arr = []
              arr = JSON.parse(dataArr[i].chipsOrder.json).orderDetail.map(item => {
                return item.medicineName
              })
              dataArr[i].drugArr = arr
            }
            this.medicineList.push(dataArr[i])
            this.drugArrList.push(dataArr[i].drugArr)
          } else {
            return
          }
        }
        // 生命支持-复选框
        for (let j = 0; j < this.treatmentList.length; j++) {
          var str = this.treatmentList[j].treatment
          var arr = eval('( ' + str + ' )')
          this.treatmentList[j].treatment = arr
          // this.saveLifeData.treatment = JSON.stringify(this.treatmentList[j].treatment)
        }
      }).catch((err) => {
        this.$message.error(err)
      })
    }
  }
}
</script>

<style scoped>
/* 边框*/
.disposal{
  width: 100%;
  padding: 20px 40px;
}
/* 其他处置text */
.text-other{
  color: #3997FB;
  margin: -40px 0 10px -10px;
  font-size: 18px;
}

/*生命支持*/
.lifeSupport{
  background-color:#f2f2f2;
  width: 100%;
  margin-top: 5px;
  padding: 10px 20px;
}
.text-life{
  font-size: 17px;
  font-weight: 400;
  margin-left: -5px;
}
/* 生命支持内部*/
.line{
  display: block;
  width: 100%;
  height: 1px;
  background-color:#949494;
  position: absolute;
  bottom: -14px;
}
.life-box{
  margin: 10px 0 30px  0px;
  font-size: 14px;
  width: 100%;
  position: relative;
}
.life-lift{
  margin: 15px 0 0px 0;
  float: left;
  width: 70%;
}
.life-right{
  margin: 5px 10px 0px 0;
  float: right;
  color: #4D4D4D;
}
.jizhen-text{
  margin: 0 20px;
}
/* 中间药物选择 */
.life-center{
  clear: both;
  margin-bottom: 10px;
  width: 100%;
  background-color: #e4e4e4;
}
.item {
  padding: 5px 30px;
}

/* --------- end -------------*/
.life-bottom{
  clear: both;
  padding-top: 10px;
}
.life-many{
  font-size: 16px;
}
.beizhutext{
  float: left;
  margin-right: 10px;
  margin-top: 10px;
}

/* 药物*/
.drug{
  background-color:#f2f2f2;
  width: 100%;
  margin-top: 5px;
  padding: 10px 20px;
}

/* 新 增  */
 .addContent{
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #DFDEE3;
  }
  .dialogStyle {
    text-align: center;
    min-width: 700px;
    /* min-height: 400px; */
  }
</style>
